home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / SimpleClient / frmClient.frm next >
Text File  |  2001-10-08  |  9KB  |  239 lines

  1. VERSION 5.00
  2. Begin VB.Form frmClient 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "vbSimple Client"
  5.    ClientHeight    =   4470
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5400
  9.    Icon            =   "frmClient.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4470
  14.    ScaleWidth      =   5400
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Frame Rules 
  17.       Caption         =   "Rules"
  18.       Height          =   855
  19.       Left            =   60
  20.       TabIndex        =   6
  21.       Top             =   120
  22.       Width           =   5295
  23.       Begin VB.Label Label1 
  24.          BackStyle       =   0  'Transparent
  25.          Caption         =   $"frmClient.frx":0442
  26.          Height          =   615
  27.          Index           =   1
  28.          Left            =   60
  29.          TabIndex        =   7
  30.          Top             =   180
  31.          Width           =   5055
  32.       End
  33.    End
  34.    Begin VB.CommandButton cmdExit 
  35.       Cancel          =   -1  'True
  36.       Caption         =   "Exit"
  37.       Height          =   375
  38.       Left            =   3143
  39.       TabIndex        =   5
  40.       Top             =   4020
  41.       Width           =   1215
  42.    End
  43.    Begin VB.CommandButton cmdFace 
  44.       Caption         =   "Make Faces"
  45.       Default         =   -1  'True
  46.       Height          =   375
  47.       Left            =   1043
  48.       TabIndex        =   4
  49.       Top             =   4020
  50.       Width           =   1215
  51.    End
  52.    Begin VB.TextBox txtUserInfo 
  53.       BackColor       =   &H8000000F&
  54.       Height          =   1935
  55.       Left            =   60
  56.       Locked          =   -1  'True
  57.       MultiLine       =   -1  'True
  58.       ScrollBars      =   2  'Vertical
  59.       TabIndex        =   1
  60.       Top             =   1980
  61.       Width           =   5295
  62.    End
  63.    Begin VB.Frame Frame1 
  64.       Caption         =   "User Stats"
  65.       Height          =   915
  66.       Left            =   60
  67.       TabIndex        =   0
  68.       Top             =   1020
  69.       Width           =   5235
  70.       Begin VB.Label lblSession 
  71.          BackStyle       =   0  'Transparent
  72.          Height          =   255
  73.          Left            =   120
  74.          TabIndex        =   3
  75.          Top             =   240
  76.          Width           =   4935
  77.       End
  78.       Begin VB.Label lblStats 
  79.          BackStyle       =   0  'Transparent
  80.          Height          =   255
  81.          Left            =   120
  82.          TabIndex        =   2
  83.          Top             =   540
  84.          Width           =   4995
  85.       End
  86.    End
  87. End
  88. Attribute VB_Name = "frmClient"
  89. Attribute VB_GlobalNameSpace = False
  90. Attribute VB_Creatable = False
  91. Attribute VB_PredeclaredId = True
  92. Attribute VB_Exposed = False
  93. Option Explicit
  94. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  95. '
  96. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  97. '
  98. '  File:       frmClient.frm
  99. '
  100. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  101. Implements DirectPlay8Event
  102. Private Enum MsgTypes
  103.     Msg_NoOtherPlayers
  104.     Msg_NumPlayers
  105.     Msg_SendWave
  106. End Enum
  107.  
  108. Private Sub cmdExit_Click()
  109.     Unload Me
  110. End Sub
  111.  
  112. Private Sub cmdFace_Click()
  113.     'Now we just need to 'make faces'
  114.     Dim oMsg() As Byte, lOffset As Long
  115.     lOffset = NewBuffer(oMsg)
  116.     AddDataToBuffer oMsg, CByte(1), SIZE_BYTE, lOffset
  117.     dpc.Send oMsg, 0, DPNSEND_NOLOOPBACK
  118. End Sub
  119.  
  120. Private Sub Form_Load()
  121.         
  122.     Set DPlayEventsForm = New DPlayConnect
  123.     'First lets get the dplay connection started
  124.     If Not DPlayEventsForm.StartClientConnectWizard(dx, dpc, AppGuid, 10, Me) Then
  125.         Cleanup
  126.         End
  127.     End If
  128.  
  129. End Sub
  130.  
  131. Private Sub Form_Unload(Cancel As Integer)
  132.     Me.Hide
  133.     DPlayEventsForm.DoSleep 50
  134.     Cleanup
  135. End Sub
  136.  
  137. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  138.     'VB requires that we must implement *every* member of this interface
  139. End Sub
  140.  
  141. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  142.     'VB requires that we must implement *every* member of this interface
  143. End Sub
  144.  
  145. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  146.     'VB requires that we must implement *every* member of this interface
  147. End Sub
  148.  
  149. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  150.     Dim AppDesc As DPN_APPLICATION_DESC
  151.     
  152.     If dpnotify.hResultCode <> 0 Then
  153.         'For some reason we could not connect.  All available slots must be closed.
  154.         MsgBox "Connect Failed.  Error: 0x" & CStr(Hex$(dpnotify.hResultCode)) & "  - This sample will now close.", vbOKOnly Or vbCritical, "Closing"
  155.         DPlayEventsForm.CloseForm Me
  156.     Else
  157.         AppDesc = dpc.GetApplicationDesc(0)
  158.         Me.Caption = AppDesc.SessionName
  159.         lblSession = "Session Name: " & AppDesc.SessionName
  160.         lblStats.Caption = "Total clients: " & CStr(AppDesc.lCurrentPlayers) & "/" & CStr(AppDesc.lMaxPlayers)
  161.     End If
  162. End Sub
  163.  
  164. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  165.     'VB requires that we must implement *every* member of this interface
  166. End Sub
  167.  
  168. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  169.     'VB requires that we must implement *every* member of this interface
  170. End Sub
  171.  
  172. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  173.     'VB requires that we must implement *every* member of this interface
  174. End Sub
  175.  
  176. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  177.     'VB requires that we must implement *every* member of this interface
  178. End Sub
  179.  
  180. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  181.     'VB requires that we must implement *every* member of this interface
  182. End Sub
  183.  
  184. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  185.     'VB requires that we must implement *every* member of this interface
  186. End Sub
  187.  
  188. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  189.     'VB requires that we must implement *every* member of this interface
  190. End Sub
  191.  
  192. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  193.     'VB requires that we must implement *every* member of this interface
  194. End Sub
  195.  
  196. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  197.     'VB requires that we must implement *every* member of this interface
  198. End Sub
  199.  
  200. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  201.     'VB requires that we must implement *every* member of this interface
  202. End Sub
  203.  
  204. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  205.     'The server is telling us something.  What?
  206.     Dim sPlayer As String, lOffset As Long
  207.     Dim lMsg As Long, lNum As Long, lMax As Long
  208.     
  209.     GetDataFromBuffer dpnotify.ReceivedData, lMsg, LenB(lMsg), lOffset
  210.     Select Case lMsg
  211.     Case Msg_NumPlayers
  212.         GetDataFromBuffer dpnotify.ReceivedData, lNum, LenB(lNum), lOffset
  213.         GetDataFromBuffer dpnotify.ReceivedData, lMax, LenB(lMax), lOffset
  214.         lblStats.Caption = "Total clients: " & CStr(lNum) & "/" & CStr(lMax)
  215.     Case Msg_NoOtherPlayers
  216.         txtUserInfo.Text = txtUserInfo.Text & "There are no other players to make funny faces at!" & vbCrLf
  217.         txtUserInfo.SelStart = Len(txtUserInfo.Text)
  218.     Case Msg_SendWave
  219.         'The only data we will receive is player info
  220.         sPlayer = GetStringFromBuffer(dpnotify.ReceivedData, lOffset)
  221.         'Append the data to the end of the line, and autoscroll there
  222.         txtUserInfo.Text = txtUserInfo.Text & sPlayer & " is making faces at you!" & vbCrLf
  223.         txtUserInfo.SelStart = Len(txtUserInfo.Text)
  224.     End Select
  225. End Sub
  226.  
  227. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  228.     'VB requires that we must implement *every* member of this interface
  229. End Sub
  230.  
  231. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  232.     If dpnotify.hResultCode = DPNERR_HOSTTERMINATEDSESSION Then
  233.         MsgBox "The host has terminated this session.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  234.     Else
  235.         MsgBox "This session has been lost.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  236.     End If
  237.     DPlayEventsForm.CloseForm Me
  238. End Sub
  239.